var thisVinfo;
var VehicleInfoMediator = Objs("view.VehicleInfoMediator",
	Mediator,
{

	initialize: function( name, viewComponent )
	{ 
		VehicleInfoMediator.$super.initialize.call( this, name, viewComponent );
    	this.VProxy = this.facade.retrieveProxy( ProxyNames.VEHICLE_PROXY );
		this.assetProxy = this.facade.retrieveProxy( ProxyNames.INITIAL_PROXY );
		this.registerListeners();
		thisVinfo=this;
		
		
	},
	registerListeners: function()
	{  
		var vehicleInfoPageView = this.get();
		vehicleInfoPageView.addEventListener( VehicleInfoPage.ADD_PNOTE, this.addPNoteHandler, this );
		
	},
	setvalue:function()
	{	
			$('#v_year').val(vehicleSingle.year);
			$("#v_year").trigger("change");
		
		document.getElementById('v_make').value = vehicleSingle.make;
			$('select#v_make').change(function() {
				thisVinfo.assetProxy.setvmodel();
			});	
		this.assetProxy.setvmodel();
		document.getElementById('v_model').value = vehicleSingle.model;
		document.getElementById('v_mileage').value = vehicleSingle.mileage;
		document.getElementById('v_great').value = vehicleSingle.great;
		document.getElementById('v_wrong').value = vehicleSingle.wrong;
		document.getElementById('v_paper_work').value = vehicleSingle.paper_work;
		document.getElementById('v_title_name').value = vehicleSingle.title_name;
		document.getElementById('v_title_note').value = vehicleSingle.title_note;
		document.getElementById('v_ad_source').value = vehicleSingle.ad_source;
		document.getElementById('v_vin').value = vehicleSingle.vin;
		document.getElementById('v_drivetrain_type').value = vehicleSingle.drivetrain_type;
		document.getElementById('v_engine').value = vehicleSingle.engine;
		document.getElementById('v_transmission').value = vehicleSingle.transmission;
		
		document.getElementById("v_list_privatenote_vinfo").innerHTML = '';
		
		var prihtml=''
		for(var j=0;j<vehicleSingle.private_notes.length;j++)
		{ 
			prihtml+="<div class='commentBox'> <div style='border-bottom:solid 1px #CCC' id=messagehead ><strong>On " +vehicleSingle.private_notes[j].dateTime+ " " +vehicleSingle.private_notes[j].messageOwener+ " Wrote</strong></div><div id=messagedetail style='padding-bottom:10px;'>" +vehicleSingle.private_notes[j].message+ "</div></div>"; 
		}
		document.getElementById("v_list_privatenote_vinfo").innerHTML=prihtml;
		var code;
		for(i=0;i<vehicleSingle.images.length;i++)
		{ 
			
			code += "<div><div  style='background-color:white; border:#c2c2c2 solid 1px; margin:5px; width:60px; height:50px; text-align: center; float:left;border-width:1px;border-style:solid;border-color:white;   line-height: 35px; font-size: 1em;'><img style=' margin-top: 5px ' src=../" +vehicleSingle.images[i].thumpUrl+"></div></div>";
			
		}
	},
	get: function()
	{
		return this.viewComponent;
	},
	unregisterListeners: function()
	{
	},
	listNotificationInterests: function()
	{
		return [
				NotificationNames.SETVIEWVALUE,
				NotificationNames.ADD_PNOTE_SUCCESS	
		];
	},
    handleNotification: function( note )
	{ 
		
		switch (note.getName() )
		{ 
			
				case NotificationNames.SETVIEWVALUE:
					this.setvalue();
				break;
				case NotificationNames.ADD_PNOTE_SUCCESS:
					/*var array=new Array();
					array.push(note.getBody());
					alert(vehicleSingle.private_notes.length);
					for(i=0;i<vehicleSingle.private_notes.length;i++)
						array.push(vehicleSingle.private_notes[i]);
					vehicleSingle.private_notes=array;*/
					this.setpnotevalue();
					$('#privatenote-modalvinfo').modal('hide');
				break;
		}
	},
	setpnotevalue:function()
	{
		document.getElementById("v_list_privatenote_vinfo").innerHTML = '';
		var prihtml=''
		for(var j=0;j<vehicleSingle.private_notes.length;j++)
		{ 
			prihtml+="<div class='commentBox'> <div style='border-bottom:solid 1px #CCC' id=messagehead ><strong>On " +vehicleSingle.private_notes[j].dateTime+ " " +vehicleSingle.private_notes[j].messageOwener+ " Wrote</strong></div><div id=messagedetail style='padding-bottom:10px;'>" +vehicleSingle.private_notes[j].message+ "</div></div>"; 
		}
		document.getElementById("v_list_privatenote_vinfo").innerHTML=prihtml;
	},
	addPNoteHandler:function()
	{
	
		if(this.facade.hasMediator(MediatorNames.PNOTE_POP_MEDIATOR)==false)
		{								
			var pnotepopPage = new PrivateNotePage();   
			var pnotepopMediator = new PrivateNoteMediator( MediatorNames.PNOTE_POP_MEDIATOR, pnotepopPage);
			this.facade.registerMediator( pnotepopMediator );
			
		}
		 
	
	},
});

